package one.stand.controller;

import one.stand.enums.RefundStateEnum;
import one.stand.model.ResultModel;
import one.stand.request.OrdersRequest;
import one.stand.service.OrdersPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单信息
 *
 * @author
 */
@RestController
@RequestMapping("/orders")
public class OrdersController extends BaseController {

    @Autowired
    private OrdersPayService ordersPayService;

    /**
     * 修改订单退款状态1未申请，2退款申请中，3退款成功
     */
    @PostMapping("/updateRefundState")
    public ResultModel updateRefundState(@RequestBody OrdersRequest request) {

        // 确认退款
        if (RefundStateEnum.REFUND_SUCCESS.getCode().equals(request.getRefundState())) {
            ordersPayService.refund(request.getOrdersId());
        } else if (RefundStateEnum.REFUND_APPLY.getCode().equals(request.getRefundState())) {
            ordersService.refundApply(request.getOrdersId(), request.getRefundRemark());
        } else if (RefundStateEnum.NO_REFUND.getCode().equals(request.getRefundState())) {
            ordersService.refundApplyCancel(request.getOrdersId());
        }

        return ResultModel.success();
    }

    /**
     * 退款（回调）
     */
    @PostMapping("/backRefund")
    public String backRefund(@RequestParam String request) {
        return ordersService.backRefund(request);
    }
}
